import {
  addAddressAPI
} from '../../../api/address'

Page({
  data: {
    name: '',
    address: '',
    phone: '',
    userId: 0
  },
  onLoad(options) {
    let user = wx.getStorageSync('user')
    if (user) {
      this.setData({
        userId: user.id
      })
    }
  },
  onSubmit() {
    let address = {
      name: this.data.name,
      address: this.data.address,
      phone: this.data.phone,
      userId: this.data.userId,
    }
    console.log(address);
    addAddressAPI(address).then(res => {
      if (res.code == 200) {
        wx.showToast({
          title: '添加成功',
        })
        wx.navigateBack()
      }
    })
  }
})